package ai.yue.open.service.cd.service;

import ai.yue.library.base.convert.Convert;
import ai.yue.library.base.view.R;
import ai.yue.library.base.view.Result;
import ai.yue.library.web.util.ServletUtils;
import ai.yue.open.service.cd.entity.Workload;
import ai.yue.open.service.cd.ipo.WorkloadIPO;
import ai.yue.open.service.cd.mapper.WorkloadMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 工作负载
 *
 * @author yl-yue
 * @since  2023/2/7
 */
@Service
public class WorkloadService extends ServiceImpl<WorkloadMapper, Workload> {

    public Result<?> insert(WorkloadIPO workloadIPO) {
        boolean save = save(Convert.toJavaBean(workloadIPO, Workload.class));
        return R.success(save);
    }

    public Result<?> deleteById(Long id) {
        return R.success(removeById(id));
    }

    public Result<?> deleteByIds(List<Long> ids) {
        return R.success(removeByIds(ids));
    }

    public Result<?> updateById(WorkloadIPO workloadIPO) {
        return R.success(updateById(Convert.toJavaBean(workloadIPO, Workload.class)));
    }

    public Result<?> page(String namespace) {
        PageHelper.startPage(ServletUtils.getRequest());
        List<Workload> workloadList = super.getBaseMapper().page(namespace);
        return R.success(PageInfo.of(workloadList));
    }

}
